package com.woniuxy.happylife.datastore.controller;

import com.github.pagehelper.PageHelper;
import com.woniuxy.happylife.datastore.service.ReviewService;
import com.woniuxy.happylife.entity.ActivityRelease;
import com.woniuxy.happylife.entity.PageRequest;
import com.woniuxy.happylife.entity.ResponseEntity;
import com.woniuxy.happylife.entity.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 活动、用户动态审核controller
 */
@RestController
@RequestMapping("/review")
public class ReviewController {

    /**
     * 审核service
     */
    @Resource
    ReviewService reviewServiceImpl;

    /**
     * 活动审核
     * @param user
     * @param rid
     * @return
     */
    @RequestMapping("/releaseReview")
    public ResponseEntity releaseReview(User user,//前端的当前用户
                                        @RequestParam("ReleaseId") Integer rid){//releaseId 为前端点击某个活动的审批按钮时，传过来的活动id

        ActivityRelease activityRelease = new ActivityRelease();
        activityRelease.setId(rid);
        activityRelease.setReleaseReviewStatus("已审核");
        activityRelease.setReviewUser(user);
        int i = reviewServiceImpl.reviewRelease(activityRelease);
        if (i != 0){
            return new ResponseEntity(200, "审核成功", null);
        }else {
            return new ResponseEntity(1000, "审核失败", null);
        }


    }

    /**
     * 活动审核页面的查询活动
     * @param pageRequest
     * @return
     */
    @RequestMapping("/findRelease")
    public ResponseEntity findRelease(@RequestBody PageRequest<ActivityRelease> pageRequest){//pageRequest分页实体类

        //分页参数
        int currentPage = pageRequest.getCurrentPage();
        int limit = pageRequest.getLimit();
        //条件查询需要的参数
        ActivityRelease activityRelease = pageRequest.getData();
        //分页查询
        PageHelper.startPage(currentPage,limit);
        List<ActivityRelease> releaseList = reviewServiceImpl.findRelease(activityRelease);
        if (releaseList.size() != 0){
            return new ResponseEntity(200, "查询成功", releaseList);
        }else{
            return new ResponseEntity(200, "查询失败", null);
        }
    }
}
